import os, sys, cv2, random
import matplotlib.pyplot as plt
from imgaug import augmenters as iaa

augseq = iaa.Sequential([
               iaa.Crop(px=(0,16)),
               iaa.Fliplr(0.5),
               iaa.GaussianBlur(sigma=(0, 3.0))
               ])
# crop
augcrop = iaa.Crop(px=(0, 20))

# Hue
aughue = iaa.AddToHue((-15, 15))

def plot_images(imgs1, imgs2, r, c, name):
  fig, axes = plt.subplots(r, c)
  for i in range(r):
      axes[i, 0].imshow(imgs1[i])
      axes[i, 0].axis("off")
      axes[i, 1].imshow(imgs2[i])
      axes[i, 1].axis("off")
  fig.savefig("{}.png".format(name))
  plt.close()
  
  
if __name__ == "__main__":
  
  abspath = "/home/liucf/Pyprojects/Datasets/libooks/"
  img_files = os.listdir(abspath)
  batch_imgs = []
  for img_file in random.sample(img_files, 8):
    img = cv2.imread(os.path.join(abspath, img_file))
    img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
    batch_imgs.append(img)
  # batch_auged = augseq(images=batch_imgs)
  batch_auged = augcrop(images=batch_imgs)
  
  plot_images(batch_imgs, batch_auged, 8, 2, "cmp")
  
